﻿<!--#include file="const.asp"-->
<%
'====================================================================
' 感谢使用晴天3G智能建站系统..
' 作者:梁永强.QQ:766750857
' 官方网址:wap.qt3g.com
' 声明:软件版权归作者所有,没有经过作者本人同意不得非法破解和传播本程序
'====================================================================
%>


<%
if sid="Null" then
	Response.Redirect "login.asp"
	Response.end
end if
IF  Request.QueryString("Action")="login" Then
	call login
else
	call index
end if
end Function



Function index
	dim page
    		Page = Request("page")      '当前页数
    		If Page = "" Then Page = 1
   		If Not IsNumeric(Page) Then Page = 1
    		Page = CLng(Page)
    		If Page < 1 Then Page = 1
	dim  rs2,sql2,Runtxt,classid,i
    		classid = Request("classid")
    		If classid = "" Then classid = 0
   		If Not IsNumeric(classid) Then classid = 0
    		classid = CLng(classid)
    		If classid < 0 Then classid = 0

	Runtxt=qingtian.RunStr


%>
	<card title="添加新文章"><p align="left">
直接添加新文章<br/><a href="addviewlist1.asp?Page=<%=Page%>&amp;classid=<%=classid%>&amp;sid=<%=sid%>">进入上传新文章</a><br/>---------------<br/>
   	分类
	<%
	  set rs2=server.CreateObject("adodb.recordset")
	  sql2="select id,name from qingtian_class where Ext=7"
	  rs2.open sql2,conn,1,1
	  if not (rs2.bof and rs2.eof) then
	  For i=1 to rs2.RecordCount
		if i=1 then
		%><%if cint(classid)>0 then%>
		<select name="cid<%=Runtxt%>" value="<%=classid%>">
		<%else%>
		<select name="cid<%=Runtxt%>" value="<%=rs2("id")%>">
		<%end if%>
		<%
		end if
		%>
		<option value="<%=rs2("id")%>"><%=qingtian.utf8(rs2("name"))%></option>
		<%
	  Rs2.MoveNext
	  Next
	else
	%>
		<select name="cid<%=Runtxt%>" value="">
	<%

	  end if
	  Rs2.close
	  set rs2=nothing
	%>
	</select><br/>
	文章推荐：
   	<select name="tuijian<%=Runtxt%>" value="0">
	<option value="0">不推荐</option>
	<option value="1">推荐</option>
	</select><br/>

	文章标题：<br/>
	<input emptyok="true"  name="name<%=Runtxt%>"  value="" type="text"/><br/>
	文章内容：<br/>
	<input emptyok="true"  name="txt<%=Runtxt%>"  value="" type="text"/><br/>
	金币购买：
   	<select name="vip<%=Runtxt%>" value="0">
	<option value="0">否</option>
	<option value="1">是</option>
	</select><br/>
	购买金币：<br/>
	<input emptyok="true"  name="zf<%=Runtxt%>"  value="0" type="text"/><br/>
	VIP是否需要购买：
   	<select name="vipgm<%=Runtxt%>" value="0">
	<option value="0">否</option>
	<option value="1">是</option>
	</select><br/>
	文章作者：<br/>
	<input emptyok="true"  name="zuozhe<%=Runtxt%>"  value="佚名" type="text"/><br/>
	文章来源：<br/>
	<input emptyok="true"  name="laiyuan<%=Runtxt%>"  value="本站整理" type="text"/><br/>


	<anchor>确定提交
    	<go href="addviewlist.asp?Action=login&amp;classid=<%=classid%>&amp;page=<%=page%>&amp;sid=<%=sid%>" method='post'>
        <postfield name="cid" value="$(cid<%=Runtxt%>)"/>
        <postfield name="name" value="$(name<%=Runtxt%>)"/>
        <postfield name="tuijian" value="$(tuijian<%=Runtxt%>)"/>
        <postfield name="txt" value="$(txt<%=Runtxt%>)"/>
        <postfield name="viphy" value="$(viphy<%=Runtxt%>)"/>
        <postfield name="vipgm" value="$(vipgm<%=Runtxt%>)"/>
        <postfield name="vip" value="$(vip<%=Runtxt%>)"/>
        <postfield name="zf" value="$(zf<%=Runtxt%>)"/>
        <postfield name="zuozhe" value="$(zuozhe<%=Runtxt%>)"/>
        <postfield name="laiyuan" value="$(laiyuan<%=Runtxt%>)"/>
    	</go>
	</anchor><br/>

-------------<br/>
<a href='viewlist.asp?classid=<%=classid%>&amp;page=<%=page%>&amp;sid=<%=sid%>'>返回文章管理</a><br/>
<a href='index.asp?sid=<%=sid%>'>后台管理首页</a><br/>
<%
End Function


Function login
	dim page
    		Page = Request("page")      '当前页数
    		If Page = "" Then Page = 1
   		If Not IsNumeric(Page) Then Page = 1
    		Page = CLng(Page)
    		If Page < 1 Then Page = 1

		dim rs,sql,errs,classid,fleg,Path,txtid
    		classid = Request("classid")
    		If classid = "" Then classid = 0
   		If Not IsNumeric(classid) Then classid = 0
    		classid = CLng(classid)
    		If classid < 0 Then classid = 0

		dim cid,name,tuijian,txt,vip,zf,zuozhe,laiyuan,viphy
        cid=Request.form("cid")
        name=Request.form("name")
        tuijian=Request.form("tuijian")
        txt=Request.form("txt")
        vip=Request.form("vip")
        zf=Request.form("zf")
        zuozhe=Request.form("zuozhe")
        laiyuan=Request.form("laiyuan")
 	viphy=TRim(Request.Form("viphy"))
 


		errs=""

		if len(name)=0  then errs=errs & "文章标题不能为空<br/>"
		if len(txt)=0  then errs=errs & "文章内容不能为空<br/>"
		if cid=""  then errs=errs&"分类不能为空<br/>"
		if not isnumeric(classid) then errs=errs&"分类必须为数字<br/>"
		if tuijian=""  then errs=errs&"推荐不能为空<br/>"
		if not isnumeric(tuijian) then errs=errs&"推荐必须为数字<br/>"
		if vip=""  then errs=errs&"VIP不能为空<br/>"
		if not isnumeric(vip) then errs=errs&"VIP必须为数字<br/>"
		if zf=""  then errs=errs&"金币不能为空<br/>"
		if not isnumeric(zf) then errs=errs&"金币必须为数字<br/>"




	%>
	<card id="login" title="添加新文章" ontimer="viewlist.asp?classid=<%=classid%>&amp;page=<%=page%>&amp;sid=<%=sid%>"><timer value="20"/>
		<p align="left">
	<%
	IF len(errs)=0 then


		Path="article/" & year(now()) & "/" & month(now()) & "/" & day(now()) & "/" & classid & "/"
		Set Rs = Server.CreateObject("Adodb.Recordset")
		Sql = "SELECT [fleg],[addtime],[path],[pathcount] from qingtian_class where id="&cid
		Rs.Open Sql,conn,1,3
		if not (rs.bof and rs.eof)  then
			fleg=rs("fleg")
			if day(rs("addtime"))=day(now()) then
				if rs("pathcount")>500 then
					Path=Path  & rs("path")+1 & "/"
					rs("path")=rs("path")+1
					rs("pathcount")=1
				else
					Path=Path  & rs("path") & "/"
					rs("pathcount")=rs("pathcount")+1
				end if

			else
				rs("addtime")=now()
				rs("path")=1
				rs("pathcount")=1

				Path=Path  & rs("path") & "/"
			end if
			rs.update
		else
			Path=Path & "1/"
			fleg=0
		end if
		rs.Close
		Set rs = Nothing


			set rs=server.CreateObject("adodb.recordset")
			sql="select top 1 id from qingtian_viewli  order by id desc"
			rs.open sql,conn,1,1
			if not (rs.bof and rs.eof) then
				txtid=rs("id")+1
			else
				txtid=1
			end if
			rs.Close
			Set rs = Nothing

		qingtian.CreateFolder Path
		path=path & txtid & ".txt"
		qingtian.CreateFile txt,path


		set rs=Server.CreateObject("ADODB.Recordset")
		Sql = "select *  FROM qingtian_viewli"
		rs.open sql,conn,1,3
		rs.addnew()

			rs("urls")=Path
			rs("flegid")=fleg
			rs("tuijian")=tuijian
			rs("name")=name
			rs("classid")=cid
			rs("zf")=zf
			rs("vip")=vip
			rs("zuozhe")=zuozhe
			rs("laiyuan")=laiyuan
		rs.update()
		rs.Close
		Set rs = Nothing
		%>添加新文章成功!<br/><%

	else%>
		<%=errs%>
		<a href="addviewlist.asp?classid=<%=classid%>&amp;page=<%=page%>&amp;sid=<%=sid%>">返回修改</a><br/>
<%	end if
%>
<a href='viewlist.asp?classid=<%=classid%>&amp;page=<%=page%>&amp;sid=<%=sid%>'>返回文章管理</a><br/>
<a href='index.asp?sid=<%=sid%>'>后台管理首页</a><br/>
<%
end Function 


%>
